/***********************************************************************
 * 	Copyright @ 2011 Zhejiang Yutian Technology Co.,Ltd
 ==================================================================
 Project:        IMSClient
 FileName:       UncaughtException.java
 Describtion:    文件描述
 Author:         xufei
 Create Date:    2014-5-6 下午4:28:04
 *********************************************************************/
package com.jason.platform.supervision.exception;

import com.jason.platform.supervision.BootApp;
import com.jason.platform.supervision.log.Log;

/**
 * @ClassName: UncaughtException
 * @Description: 进程中未捕获异常控制
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2015-7-23 11:15:59
 */
public class UncaughtException implements Thread.UncaughtExceptionHandler {

    private static final String TAG = "UncaughtException";
    /**
     * 异常句柄
     */
    @SuppressWarnings("unused")
    private Thread.UncaughtExceptionHandler mUeHandler;

    public UncaughtException() {
        Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
        this.mUeHandler = handler;
    }

    @Override
    public void uncaughtException(Thread thread, Throwable throwable) {
        Log.e(TAG, "", throwable);
        onFC();
    }

    private void onFC() {
        BootApp bootApp = BootApp.getInstance();
        if (bootApp != null) {
            Log.e(TAG, "UncaughtException-->onFC");
            bootApp.onFC();
        } else {
            Log.e(TAG, "UncaughtException-->killProcess");
            int pid = android.os.Process.myPid();
            android.os.Process.killProcess(pid);
        }
    }
}
